package logic

import (
	"context"
	"order/internal/svc"
	"order/model/mysql"
	"order/order"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderCreateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewOrderCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderCreateLogic {
	return &OrderCreateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *OrderCreateLogic) OrderCreate(in *order.OrderCreateRequest) (*order.OrderCreateResponse, error) {
	// todo: add your logic here and delete this line
	m := mysql.Order{
		GoodId:  int(in.GoodId),
		GoodNum: int(in.GoodNum),
		Amount:  in.Amount,
		OrderSn: in.OrderSn,
		PayType: int(in.PayType),
	}
	err := m.OrderCreate()
	if err != nil {
		return nil, err
		logx.Error(err)
	}

	return &order.OrderCreateResponse{Id: int64(m.ID)}, nil
}
